//
//  GRJBlocksKitViewController.m
//  GRJTolCayFrwk
//
//  Created by 易上云 on 2017/3/10.
//  Copyright © 2017年 Global Barter. All rights reserved.
//

#import "GRJBlocksKitViewController.h"

#import "BlocksKit.h"
#import "NSArray+BlocksKit.h"

@interface GRJBlocksKitViewController ()

@property (nonatomic, assign) NSInteger result;

@end

@implementation GRJBlocksKitViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"BlicksKit";
    //1 为一个已经存在的类添加属性  AssociatedObject
    [self addProperty];
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [@[@1,@2,@3] enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSLog(@"%@-->%@",obj,[NSThread currentThread]);
    }];
    
    [@[@1,@2,@3] bk_each:^(id obj) {
        NSLog(@"%@-->%@",obj,[NSThread currentThread]);
    }];
    
    
    
    [self myBlock:^(id obj) {
        NSLog(@"-----<><>>>%@",obj);
    }];
    
    [self addNumber:^NSInteger(NSInteger result) {
        result += 5;
        NSLog(@"----{result}--%ld",result);
        return result;
        
    }];
    
    NSLog(@"----{{{--%ld",self.result);  //后打印
}


//为一个已经存在的类添加属性  AssociatedObject
-(void)addProperty{
    NSObject *test = [[NSObject alloc]init];
    [test bk_associateValue:@"GuRuijie" withKey:@"name"];
    NSLog(@"%@",[test bk_associatedValueForKey:@"name"]);
    
}


-(void)myBlock:(void (^)(id obj)) block{
    NSLog(@"--->>%@",block);
    block(@2);
}

-(void)addNumber:(NSInteger (^)(NSInteger result))block{
    NSLog(@"%ld",self.result);  //0
    block(5);
    NSLog(@"----%ld",self.result);  //先打印
}
@end
